/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Enum.LoaiNguoiDungEnum;
import java.util.List;
import org.hibernate.Session;
import pojo.NguoiDung;
import util.NewHibernateUtil;

/**
 *
 * @author 0
 */
public class NguoiDungDAO extends BaseDAO{
    public static List<?> TimKiem(Class<?> clazz,NguoiDung nguoiDung) throws Exception{
        List<?> list=null;
        Session session=NewHibernateUtil.getSessionFactory().openSession();        
        if(nguoiDung.getLoaiNguoiDung().getId()==LoaiNguoiDungEnum.Admin.getCode() || !existCuaHang(clazz.getFields())){
            list=session.createQuery(String.format("from %s o where o.isDelete=false or o.isDelete=null", clazz.getName())).list();
        }
        else{
            list=session.createQuery(String.format("from %s o where (o.isDelete=false or o.isDelete=null) and o.cuaHang.id=%d", clazz.getName(),nguoiDung.getLoaiNguoiDung().getId())).list();
        }
        session.close();
        return list;
    }
}
